<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="header">
<div th:fragment="content">

<!-- 任务列表 -->
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h4>填报任务列表</h4></div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-bordered table-striped table-vcenter" style="text-align: center">
                        <thead>
                            <tr>
                                <th  style="text-align: center;width: 64px;">编号</th>
                                <th style="text-align: center;width: 264px;">任务名称</th>
                                <th style="text-align: center;width: 264px;">发布时间</th>
                                <th style="text-align: center;width: 264px;">填报范围</th>
                                <th style="text-align: center;width: 86px;">发布人</th>
                                <th style="text-align: center;width: 86px;">任务状态</th>
                                <th style="text-align: center;width: 102px;">操作</th>
                            </tr>
                        </thead>
                        <tbody>

                        <!--/*@thymesVar id="task" type="cn.edu.gues.infosystam.entity.Task"*/-->
                        <tr th:each="task : ${taskPage.getRecords()}" th:id="'task-'+${task.getTaskId()}">
                            <td th:text="${task.getTaskId()}">task_id</td>
                            <td th:text="${task.getTaskName()}">task_name</td>
                            <td><code th:text="${#dates.format(task.getGmtCreate(), 'yyyy-MM-dd HH:mm:ss')}">gmtCreate</code></td>
                            <td th:text="${task.getTaskRange()}">task_range</td>
                            <td th:text="${task.getTname()}">task_tname</td>
                            <td th:text="${(task.getTaskState()==1)?'正在进行':'已完成'}" th:class="${(task.getTaskState()==1)?'text-danger':'text-success'}">任务启动</td>
                            <td>
                                <div class="btn-group">
                                    <a class="btn btn-xs btn-default" th:href="'/Task/Detail/'+${task.getTaskId()}" title="查看" data-toggle="tooltip">
                                        <i class="mdi mdi-eye"></i>
                                    </a>
                                    <a class="btn btn-xs btn-default" th:href="'javascript:delAjax(\''+${task.getTaskId()}+'\')'" title="删除" data-toggle="tooltip">
                                        <i class="mdi mdi-window-close"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <!-- 分页码 -->
                <ul class="pagination">
                    <!-- 第一页按钮 -->
                    <li th:class="${taskPage.hasPrevious()?'':'disabled'}" >
                        <a th:href="${taskPage.hasPrevious()?('/Task/List?p='+(taskPage.getCurrent()-1)):'javascript:return false;'}">«</a>
                    </li>
                    <!-- 中间按钮 -->
                    <li th:each="i : ${#numbers.sequence(
                    (taskPage.getCurrent()>3?taskPage.getCurrent()-2:1)
                    , (taskPage.getCurrent()<(taskPage.getPages()-2)?taskPage.getCurrent()+2:taskPage.getPages())
                    )}"
                        th:class="${taskPage.getCurrent()==i?'active':''}"
                    >
                        <a th:href="'/Task/List?p='+ ${i}"
                           th:text="${i}"
                        >???</a>
                    </li>
                    <!-- 最后一页按钮 -->
                    <li  th:class="${taskPage.hasNext()?'':'disabled'}" >
                        <a th:href="${taskPage.hasNext()?('/Task/List?p='+(taskPage.getCurrent()+1)):'javascript:return false;'}">»</a>
                    </li>
                    <li><span th:text="'共 '+ ${taskPage.getCurrent()} +' / '+ ${taskPage.getPages()} +' 页' ">共 0 / 0 页</span></li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
    function delAjax(id) {
        $.ajax({
            type: "POST",
            url: "/Task/Del",
            dataType: "json",
            data: {
                "taskId": id,
            },
            success: function (data, status) {
                console.log(data)
                lightyear.loading('hide');
                if (status === "success") {
                    if (data.code === 200){
                        lightyear.notify('您成功删除了一个任务~', 'success', 1000);
                        $("#task-" + id).remove();
                    } else{
                        console.log("后端拒绝")
                        lightyear.notify(data.msg, 'danger', 3000);
                    }
                }else{
                    console.log("网络问题")
                    lightyear.notify('网络不可用，请稍候再试！！！', 'danger', 3000);
                }
            },
            error: function (xhr, errorText, errorType) {
                lightyear.loading('hide');
                lightyear.notify('服务器错误，请稍后再试~', 'danger', 2000);
            }
        });
    }
</script>
</div>
</html>
